<template>
    <div class="edu-page-warp">
        <InnerBreadcrumb v-model="indexKey" :path="breadPath" :showBack="true" />
        <div v-if="indexKey == '0'">
            <condition-card @reset="reset" @search="onSubmit" label-width="80px">
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.grade')">
                            <el-date-picker
                                clearable
                                v-model="queryForm.grade"
                                value-format="yyyy"
                                type="year"
                                :placeholder="$t('message.plzSelect')"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.college')">
                            <el-select
                                v-model="queryForm.faculty"
                                filterable
                                style="width:100%;height:33px"
                                clearable
                                @change="handleChangeFaculty"
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.faculty"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.major')">
                            <el-select
                                v-model="queryForm.profession"
                                filterable
                                style="width:100%;height:33px"
                                clearable
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.profession"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingLevel')">
                            <el-select
                                v-model="queryForm.trainingLevel"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.trainingLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingCategory')">
                            <el-select
                                v-model="queryForm.trainingCategory"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.trainingCategory"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('dic.degreeType')">
                            <el-select
                                v-model="queryForm.degreeType"
                                style="width:100%"
                                clearable
                                @change="handleChangeFaculty"
                            >
                                <el-option
                                    v-for="item in options.degreeType"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.formLearning')">
                            <el-select
                                v-model="queryForm.formLearning"
                                style="width:100%"
                                clearable
                            >
                                <el-option
                                    v-for="item in options.formLearning"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.enrolMethod')">
                            <el-select
                                v-model="queryForm.enrolMethodList"
                                style="width:100%"
                                multiple
                                collapse-tags 
                                clearable
                            >
                                <el-option
                                    v-for="item in options.enrolMethods"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="审核状态">
                            <el-select
                                v-model="queryForm.status"
                                style="width:100%;height:33px"
                                clearable
                                multiple
                                collapse-tags
                            >
                                <el-option
                                    v-for="item in options.approveStatus"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </condition-card>
            <el-card shadow="never">
                <div class="edu-page-title">{{title}}答辩管理列表</div>
                <el-row>
                    <el-col :span="4">
                        <el-input
                            v-model="queryForm.keyWord"
                            :placeholder="$t('score.failScoreManage.pleaseInt')"
                            @keyup.enter.native="onSubmit"
                            style="width:200px"
                        >
                            <i
                                class="el-icon-search"
                                slot="suffix"
                                style="margin-top:10px;cursor:pointer"
                                @click="onSubmit"
                            ></i>
                        </el-input>
                    </el-col>
                    <el-col :span="8">
                        <div class="empty-box" />
                    </el-col>
                    <el-col :span="12">
                        <div class="float-right">
                            <el-button @click="handleExport">{{$t('message.export')}}</el-button>
                            <el-button
                                type="primary"
                                v-if="!isStudent"
                                @click="handleBatchCheck"
                            >批量审核</el-button>
                            <el-button
                                type="primary"
                                v-if="isStudent"
                                @click="handleApply"
                            >{{$t('message.apply')}}</el-button>
                        </div>
                    </el-col>
                </el-row>
                <edu-table
                    key="students"
                    :data="students"
                    size="mini"
                    style="width:100%"
                    @page-change="handleCurrentChange"
                    :total="queryForm.total_"
                    :pageSize="queryForm.pageSize_"
                    :pageNum="queryForm.pageNum_"
                    @selection-change="handleSelectionChange"
                    :order="false"
                >
                    <el-table-column
                        fixed="left"
                        :label="$t('label.stuCode')"
                        prop="studentId"
                        width="80"
                        show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                        fixed="left"
                        :label="$t('label.stuName')"
                        prop="studentName"
                        show-overflow-tooltip
                        width="80"
                    ></el-table-column>
                    <el-table-column :label="$t('label.grade')" prop="grade" width="60"></el-table-column>
                    <el-table-column :label="$t('label.college')" show-overflow-tooltip width="120">
                        <template slot-scope="scope">{{ scope.row.facultyI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.major')" width="120" show-overflow-tooltip>
                        <template slot-scope="scope">{{ scope.row.professionI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.trainingLevel')">
                        <template slot-scope="scope">{{ scope.row.trainingLevelI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.trainingCategory')" width="100">
                        <template slot-scope="scope">{{ scope.row.trainingCategoryI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('dic.degreeType')" prop="degreeType">
                        <template slot-scope="scope">{{ scope.row.degreeTypeI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.formLearning')">
                        <template slot-scope="scope">{{ scope.row.formLearningI18n }}</template>
                    </el-table-column>
                    <el-table-column :label="$t('label.enrolMethod')" show-overflow-tooltip>
                        <template slot-scope="scope">{{ scope.row.enrolMethodsI18n }}</template>
                    </el-table-column>
                    <el-table-column label="导师" show-overflow-tooltip width="120">
                        <template slot-scope="scope">{{ scope.row.teacher }}</template>
                    </el-table-column>
                    <el-table-column label="申请时间" show-overflow-tooltip width="170">
                        <template slot-scope="scope">{{scope.row.applyTime}}</template>
                    </el-table-column>
                    <el-table-column :label="title+'答辩时间'" show-overflow-tooltip width="120">
                        <template slot-scope="scope">{{getFormatData(scope.row.defenseTime)}}</template>
                    </el-table-column>
                    <el-table-column
                        label="研究生院批准时间"
                        show-overflow-tooltip
                        width="170"
                        prop="passTime"
                    ></el-table-column>
                    <el-table-column
                        label="审核状态"
                        prop="statusName"
                        show-overflow-tooltip
                        width="120"
                    ></el-table-column>
                    <el-table-column label="当前处理人" show-overflow-tooltip width="160" v-if="isStudent">
                        <template slot-scope="scope">
                            <span v-if="scope.row.status>=5">{{scope.row.reviewerName}}({{scope.row.reviewer}})</span>
                            <!--导师-->
                            <span v-else-if="scope.row.status==4">{{scope.row.reviewerName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="当前处理人" show-overflow-tooltip width="160" v-if="!isStudent">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                v-if="scope.row.status>=5"
                                @click="handleReviewGroup(scope.row.reviewer)"
                            >{{scope.row.reviewerName}}({{scope.row.reviewer}})</el-button>
                            <!--导师-->
                            <span v-else-if="scope.row.status==4">{{scope.row.reviewerName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('message.operating')" fixed="right" width="130">
                        <template slot-scope="scope">
                            <!--0为可审核状态-->
                            <el-button
                                v-if="scope.row.isApprove==0"
                                type="text"
                                @click="handleCheck(scope)"
                            >{{$t('message.check')}}</el-button>
                            <el-button
                                type="text"
                                @click="handleDetail(scope)"
                            >{{$t('message.detail')}}</el-button>
                            <!--草稿时允许编辑-->
                            <el-button
                                type="text"
                                v-if="scope.row.status==0&&studentId==scope.row.studentId"
                                @click="handleEdit(scope)"
                            >{{$t('message.edit')}}</el-button>
                            <!--草稿时允许删除-->
                            <el-button
                                v-if="scope.row.status==0&&studentId==scope.row.studentId"
                                type="text"
                                @click="handleDelete(scope)"
                            >{{$t('message.delete')}}</el-button>
                        </template>
                    </el-table-column>
                </edu-table>
            </el-card>
        </div>
        <div v-if="indexKey == '1'">
            <el-card shadow="never">
                <div class="edu-page-title">学生信息</div>
                <hr style="margin:15px 0 10px 0" />
                <el-form
                    label-position="right"
                    label-width="120px"
                    label-suffix="："
                    id="stu-info"
                    v-if="currentStudent"
                >
                    <el-row>
                        <el-col :span="colSpan">
                            <el-form-item :label="$t('label.stuCode')">{{currentStudent.studentId}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.stuName')"
                            >{{currentStudent.studentName}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.college')"
                            >{{currentStudent.facultyI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.major')"
                            >{{currentStudent.professionI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item :label="$t('label.grade')">{{currentStudent.grade}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item label="导师">{{currentStudent.teacher}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.trainingLevel')"
                            >{{currentStudent.trainingLevelI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.trainingCategory')"
                            >{{currentStudent.trainingCategoryI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('dic.degreeType')"
                            >{{currentStudent.degreeTypeI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan">
                            <el-form-item
                                :label="$t('label.formLearning')"
                            >{{currentStudent.formLearningI18n}}</el-form-item>
                        </el-col>
                        <el-col :span="colSpan" v-if="defenseType == 1">
                                <el-form-item
                                    :label="$t('label.enrolDate')"
                                >{{currentStudent.enrolDate}}</el-form-item>
                            </el-col>
                            <el-col :span="colSpan" v-if="defenseType == 1">
                                <el-form-item
                                    :label="$t('label.expectedGraduationDate')"
                                >{{currentStudent.expectedGraduationDate}}</el-form-item>
                            </el-col>
                    </el-row>
                </el-form>
                <!--详情或审核-->
                <div v-if="currentOprType==oprType.CHECK||currentOprType==oprType.READ">
                    <hr style="margin:0 0 15px 0" />
                    <div class="edu-page-title">申请明细</div>
                    <table class="table-detail">
                        <col width="15%" />
                        <col width="85%" />
                        <tr>
                            <td class="label">
                                <span>预计{{title}}答辩时间：</span>
                            </td>
                            <td>
                                <span>{{currentStudent.defenseTime}}</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <span>原因说明：</span>
                            </td>
                            <td>
                                <span>{{currentStudent.reasonDesc}}</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <span>申请材料：</span>
                            </td>
                            <td>
                                <!-- <div
                                    :key="index"
                                    v-for="(file,index) in currentStudent.attachFile"
                                >
                                    <span>
                                        <a
                                            href="#"
                                            @click="handleDownLoad(file)"
                                        >{{getFileName(file.name)}}</a>
                                    </span>
                                </div> -->
                                <PreviewOffice
                                :newFileList="currentStudent.attachFile"
                                />
                            </td>
                        </tr>
                    </table>
                </div>
                <el-card shadow="never" v-if="currentOprType==oprType.CHECK">
                    <div class="edu-page-title">审核</div>
                    <el-form
                        label-width="150px"
                        label-suffix="："
                        ref="submitForm"
                        :model="submitForm"
                        :rules="submitRules"
                    >
                        <!--留办状态为6，留办不显示答辩时间-->
                        <el-row :gutter="20" v-if="(defenseType == 1 && currentStudent.status!=6) || defenseType == 0">
                            <el-col :span="8">
                                <el-form-item :label="'预计'+title+'答辩时间'" prop="defenseTime">
                                    <el-date-picker
                                        v-model="submitForm.defenseTime"
                                        type="date"
                                        format="yyyy-MM-dd"
                                        value-format="yyyy-MM-dd"
                                        placeholder="选择日期"
                                        style="width:100%"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="20">
                            <el-col :span="24">
                                <el-form-item label="审批意见" prop="suggestion">
                                    <el-input
                                        type="textarea"
                                        rows="4"
                                        v-model="submitForm.suggestion"
                                        style="width:100%"
                                        maxlength="400"
                                    />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row :gutter="20">
                            <el-col :span="24" style="text-align:right">
                                <el-button
                                    type="danger"
                                    @click="handleReject"
                                >{{$t('message.reject')}}</el-button>
                                <el-button type="primary" @click="handlePass">{{$t('message.pass')}}</el-button>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-card>
            </el-card>
            <!--申请或编辑-->
            <div v-if="currentOprType==oprType.CREATE||currentOprType==oprType.EDIT">
                <apply-form
                    v-if="currentStudent"
                    :defense-type="queryForm.defenseType"
                    :apply-type="queryForm.applyType"
                    ref="applyForm"
                    @close="handleReturn"
                    @success="handleSave"
                    :mayGraduatTime='mayGraduatTime'
                    :submitType="submitType"
                    :show-save-btn="true"
                    :students="[currentStudent]"
                    :edit-form="editForm"
                />
            </div>
            <el-card shadow="never" v-if="currentStudent&&currentStudent.workflowNo">
                <div class="edu-page-title">审批进度</div>
                <edu-table
                    key="prograss"
                    :pagination="false"
                    style="margin-top:10px"
                    :selection="false"
                    :data="approvalHistorys"
                >
                    <el-table-column :label="$t('message.time')" prop="approvalTime" />
                    <el-table-column label="审批人" prop="reviewerName" />
                    <el-table-column :label="$t('label.operation')" prop="processOperat" />
                    <el-table-column label="节点" prop="processNodes" />
                    <el-table-column label="说明" prop="reasonDescri" show-overflow-tooltip />
                </edu-table>
            </el-card>
        </div>
        <div id="batch-dialog">
            <edu-dialog title="批量审核" ref="batchApproveDialog" width="500px">
                <el-row>
                    <el-col :span="4">审批意见：</el-col>
                    <el-col :span="20">
                        <el-form ref="batchForm" :model="batchForm" :rules="batchRules">
                            <el-form-item prop="suggestion">
                                <el-input
                                    type="textarea"
                                    v-model="batchForm.suggestion"
                                    rows="4"
                                    maxlength="400"
                                ></el-input>
                            </el-form-item>
                        </el-form>
                    </el-col>
                </el-row>
                <template slot="buttons">
                    <el-button @click="handleBatchCancel">{{$t('message.cancel')}}</el-button>
                    <el-button @click="handleBatchReject" type="danger">{{$t('message.reject')}}</el-button>
                    <el-button @click="handleBatchPass" type="primary">{{$t('message.pass')}}</el-button>
                </template>
            </edu-dialog>
        </div>
        <edu-dialog
            title="组内用户明细"
            ref="groupUsers"
            width="800px"
            @close="handleGroupUsersClose"
            :showFooter="false"
        >
            <edu-table
                key="users"
                :data="users"
                size="mini"
                style="width:100%"
                @page-change="handleUserCurrentChange"
                :total="usersQueryForm.total_"
                :pageSize="usersQueryForm.pageSize_"
                :pageNum="usersQueryForm.pageNum_"
                :selection="false"
            >
                <el-table-column label="账号" prop="studentId" width="100"></el-table-column>
                <el-table-column label="用户名" prop="name" width="100"></el-table-column>
                <el-table-column label="联系电话" prop="phoneNumber" show-overflow-tooltip></el-table-column>
                <el-table-column label="联系邮箱" prop="email" show-overflow-tooltip></el-table-column>
                <el-table-column label="类型" width="80">
                    <template slot-scope="scope">{{getUserType(scope.row.userType)}}</template>
                </el-table-column>
            </edu-table>
        </edu-dialog>
    </div>
</template>

<script>
import { queryDic } from "common/src/api/dictionary";
import {
    selectOralDefense,
    selectStudentInfoByStuId,
    deleteOralDefenseInfo,
    exportOralDefenseInfo,
    oralApprovalHistory,
    updateDefenseTime
} from "common/src/api/culture/change";
import { downloadfile } from "common/src/api/upload";
import { approvalThrough, approvalReject } from "common/src/api/approval";
import stu from 'common/src/api/studentinfo'
import { throughBatch, rejectBatch } from "common/src/api/studentRegister";
import { getUserInfoListByGroupId } from "common/src/api/user";
import ApplyForm from "./ApplyForm";
import PreviewOffice from "common/src/components/common/PreviewOffice.vue"
import mixin from 'common/src/mixins/index';
export default {
    name: "EarlyExamManage",
    mixins: [mixin],
    components: {
        ApplyForm,
        PreviewOffice
    },
    props: {
        defenseType: {
            default: 0
        },
        submitType: {
            default: 0
        }
    },
    data: function() {
        return {
            title: this.defenseType == 0 ? "提前" : "延期",
            mayGraduatTime: null,
            queryForm: {
                defenseType: this.defenseType,
                applyType: 0,
                grade: null,
                faculty: [],
                profession: [],
                trainingLevel: null,
                trainingCategory: null,
                degreeType: null,
                formLearning: null,
                enrolMethodList: [],
                status: [],
                keyWord: null,
                pageSize_: 20,
                pageNum_: 1,
                total_: 0
            },
            options: {
                faculty: [],
                profession: [],
                trainingLevel: [],
                trainingCategory: [],
                degreeType: [],
                formLearning: [],
                enrolMethods: [],
                approveStatus: null
            },
            indexKey: 0,
            breadPath: {
                label: this.defenseType == 0 ? "提前答辩" : "延期答辩",
                key: "0",
                children: [
                    {
                        key: "1",
                        label: "新增"
                    }
                ]
            },
            students: null,
            selectStudents: [],
            isStudent: false,
            studentId: null,
            currentStudent: null,
            editForm: null,
            currentOprType: null, //当前操作类型
            oprType: {
                READ: "0", //详情
                CREATE: "1", //申请
                EDIT: "2", //编辑
                CHECK: "3" //审核
            },
            approvalHistorys: null,
            submitForm: {
                defenseTime: null,
                suggestion: null
            },
            submitRules: {
                defenseTime: {
                    required: true,
                    message:
                        this.defenseType == 0
                            ? "必须选择提前答辩时间"
                            : "必须选择延期答辩时间",
                    trigger: "change"
                },
                suggestion: {
                    validator: this.validateSuggestion,
                    trigger: "change"
                }
            },
            batchForm: {
                suggestion: null
            },
            batchRules: {
                suggestion: {
                    validator: this.validateBatchSuggestion,
                    trigger: "change"
                }
            },
            isReject: false,
            users: null,
            usersQueryForm: {
                groupId: null,
                pageSize_: 20,
                pageNum_: 1,
                total_: 0
            }
        };
    },
    mounted() {
        this.init();
        let user = this.global.mockUser || this.global.user;
        if (user.type == "2") {
            this.isStudent = true;
            this.studentId = user.uid;
        }
    },
    computed: {
        colSpan() {
            if (this.currentStudent == null) {
                return 6;
            }
            if (
                this.currentStudent.facultyI18n &&
                this.currentStudent.facultyI18n.length >= 8
            ) {
                return 8;
            }
            if (
                this.currentStudent.professionI18n &&
                this.currentStudent.professionI18n.length >= 8
            ) {
                return 8;
            }
            return 6;
        }
    },
    methods: {
        init() {
            let approveStatus = [
                {
                    label: "草稿",
                    value: "0"
                },
                {
                    label: "驳回",
                    value: "2"
                },
                {
                    label: "通过",
                    value: "3"
                },
                {
                    label: "导师审核",
                    value: "4"
                },
                {
                    label: "学院审核",
                    value: "5"
                },
                {
                    label: "留办审核",
                    value: "6"
                },
                {
                    label: "培养处审核",
                    value: "7"
                }
            ];
            this.options.approveStatus = approveStatus;
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["X_YX", "X_PYCC", "X_PYLB", "X_XWLX", "X_XXXS", "X_RXFS"]
            };
            queryDic(data).then(res => {
                if (res.code === 200) {
                    this.fill("faculty", res.data.X_YX);
                    this.fill("trainingLevel", res.data.X_PYCC);
                    this.fill("trainingCategory", res.data.X_PYLB);
                    this.fill("degreeType", res.data.X_XWLX);
                    this.fill("formLearning", res.data.X_XXXS);
                    this.fill("enrolMethods", res.data.X_RXFS);
                }
            });
            this.onSubmit();
        },
        fill(type, data) {
            for (const key in data) {
                this.options[type].push({
                    value: key,
                    label: data[key]
                });
            }
        },
        reset() {
            this.queryForm.grade = null;
            this.queryForm.faculty = [];
            this.queryForm.profession = [];
            this.queryForm.trainingLevel = null;
            this.queryForm.trainingCategory = null;
            this.queryForm.degreeType = null;
            this.queryForm.formLearning = null;
            this.queryForm.enrolMethodList = [];
            this.queryForm.status = [];
            this.queryForm.keyWord = null;
            this.options.profession.length = 0;
            this.onSubmit();
        },
        onSubmit(isFirstPage = true) {
            if (isFirstPage) {
                this.queryForm.pageNum_ = 1;
            }
            let params = _.cloneDeep(this.queryForm);
            params.faculty =
                params.faculty.length > 0 ? params.faculty.join(",") : null;
            params.profession =
                params.profession.length > 0
                    ? params.profession.join(",")
                    : null;
            params.status =
                params.status.length > 0 ? params.status.join(",") : null;
            selectOralDefense(params).then(res => {
                if (res.code == 200) {
                    this.students = res.data.list;
                    this.queryForm.total_ = res.data.total_;
                }
            });
        },
        handleCurrentChange(val) {
            this.queryForm.pageSize_ = val.pageSize;
            this.queryForm.pageNum_ = val.pageNum;
            this.onSubmit(false);
        },
        handleChangeFaculty() {
            this.options.profession = [];
            this.queryForm.profession = [];
            if (!this.queryForm.faculty) {
                return;
            }
            const data = {
                lang: this.$store.getters.language || "cn",
                type: "allChild",
                keys: ["G_ZY"],
                filter: {
                    prefix: this.queryForm.faculty,
                    specilaCode: "XY2ZY",
                    grade: null,
                    facultys: this.queryForm.faculty,
                    degreeType: this.queryForm.degreeType
                        ? [this.queryForm.degreeType]
                        : []
                }
            };
            queryDic(data).then(res => {
                if (res.code === 200) this.fill("profession", res.data.G_ZY);
            });
        },
        handleSelectionChange(val) {
            this.selectStudents = val;
        },
        handleExport() {
            let param = null;
            if (this.selectStudents.length > 0) {
                param = {
                    ids: this.selectStudents.map(s => s.id).join(","),
                    defenseType: this.queryForm.defenseType
                };
            } else {
                param = this.queryForm;
            }
            window.open(exportOralDefenseInfo(param));
        },
        handleBatchCheck() {
            if (this.selectStudents.length == 0) {
                this.$message({
                    type: "warning",
                    message: "请选择需要审批的申请"
                });
                return;
            }
            if (!this.selectStudents.every(s => s.isApprove == 0)) {
                this.$message({
                    type: "warning",
                    message: "选中学生必须都是待审核状态"
                });
                return;
            }
            let status = this.selectStudents[0].status;
            if (this.selectStudents.some(s => s.status != status)) {
                this.$message({
                    type: "warning",
                    message: "审核状态必须一致"
                });
                return;
            }
            this.$refs.batchApproveDialog.open();
            if (this.$refs.batchForm) {
                this.batchForm.suggestion = null;
                this.$refs.batchForm.clearValidate();
            }
        },
        handleApply() {
            selectStudentInfoByStuId(this.studentId).then(res => {
                if (res.code == 200) {
                    this.breadPath.children[0].label = this.$t("message.add");
                    this.editForm = null;
                    this.currentStudent = res.data[0];
                    this.mayGraduatTime = res.data[0].expectedGraduationDate
                    this.indexKey = "1";
                    this.currentOprType = this.oprType.CREATE;
                }
            });
        },
        handleCheck(scope) {
            this.breadPath.children[0].label = this.$t("message.check");
            this.currentStudent = _.cloneDeep(scope.row);
            if(scope.row.attachFile && scope.row.attachFile.length > 0) {
            if((scope.row.attachFile.substring(0,1)).toString() === '[') {
            this.currentStudent.attachFile = JSON.parse(scope.row.attachFile)
            } else {
            let filesList = []
            let evidList = scope.row.attachFile.split(",")
            evidList.map(files=> {
                filesList.push(
                {
                    name: files,
                    url: files
                }
                )
            })
            this.currentStudent.attachFile = filesList
            }
        }
            this.indexKey = "1";
            this.currentOprType = this.oprType.CHECK;
            this.currentStudent.defenseTime = moment(
                scope.row.defenseTime
            ).format("YYYY-MM-DD");
            this.submitForm.suggestion = null;
            this.submitForm.defenseTime = this.currentStudent.defenseTime;
            this.bindApproveHistory(scope.row.workflowNo);
        },
        handleDetail(scope) {
            this.breadPath.children[0].label = this.$t("message.detail");
            this.currentStudent = _.cloneDeep(scope.row);
            if(scope.row.attachFile && scope.row.attachFile.length > 0) {
            if((scope.row.attachFile.substring(0,1)).toString() === '[') {
            this.currentStudent.attachFile = JSON.parse(scope.row.attachFile)
            } else {
            let filesList = []
            let evidList = scope.row.attachFile.split(",")
            evidList.map(files=> {
                filesList.push(
                {
                    name: files,
                    url: files
                }
                )
            })
            this.currentStudent.attachFile = filesList
            }
        }
            this.indexKey = "1";
            this.currentOprType = this.oprType.READ;
            this.currentStudent.defenseTime = moment(
                scope.row.defenseTime
            ).format("YYYY-MM-DD");
            this.bindApproveHistory(scope.row.workflowNo);
        },
        handleEdit(scope) {
            this.breadPath.children[0].label = this.$t("message.edit");
            this.editForm = _.cloneDeep(scope.row);
            this.currentStudent = _.cloneDeep(scope.row);
            if(scope.row.attachFile && scope.row.attachFile.length > 0) {
            if((scope.row.attachFile.substring(0,1)).toString() === '[') {
            this.editForm.attachFile = JSON.parse(scope.row.attachFile)
            } else {
            let filesList = []
            let evidList = scope.row.attachFile.split(",")
            evidList.map(files=> {
                filesList.push(
                {
                    name: files,
                    url: files
                }
                )
            })
            this.editForm.attachFile = filesList
            }
        }
            this.indexKey = "1";
            this.currentOprType = this.oprType.EDIT;
        },
        handleDelete(scope) {
            this.$delConfirm().then(() => {
                deleteOralDefenseInfo({ ids: [scope.row.id] }).then(res => {
                    if (res.code == 200) {
                        this.$message({
                            type: "success",
                            message: this.$t("message.deleteSuccess")
                        });
                        this.onSubmit();
                    }
                });
            });
        },
        handleReturn() {
            this.indexKey = "0";
            this.currentOprType = null;
            this.onSubmit();
        },
        handleSave() {
            this.indexKey = "0";
            this.currentOprType = null;
            this.onSubmit();
        },
        handleDownLoad(file) {
            // downloadfile(file);
        let url = '/api/commonservice/obsfile/downloadfile?objectkey=' + file.url  
        let name = file.name
        stu.downTemplate(name, url);
        },
        handlePass() {
            this.isReject = false;
            this.$refs.submitForm.validate(valid => {
                if (!valid) {
                    return;
                }
                let params = [
                    {
                        id: this.currentStudent.id,
                        defenseTime: this.submitForm.defenseTime,
                        workflowNo: this.currentStudent.workflowNo
                    }];
                updateDefenseTime(params).then(res => {
                    if (res.code == 200) {
                       
                        this.indexKey = "0";
                        this.currentOprType = null;
                        approvalThrough({
                                no: this.currentStudent.workflowNo,
                                content: this.submitForm.suggestion,
                                approveAttachment: []
                                }).then(res => {
                                    if (res.code == 200) {
                                        this.$message({
                                            type: "success",
                                            message: "审批通过"
                                        });
                                         this.onSubmit();
                                    }
                                })
                            }
                    });
            });
        },
        handleReject() {
            this.isReject = true;
            this.$refs.submitForm.validate(valid => {
                if (!valid) {
                    return;
                }
                approvalReject({
                    no: this.currentStudent.workflowNo,
                    content: this.submitForm.suggestion,
                    approveAttachment: []
                }).then(res => {
                    if (res.code == 200) {
                        this.$message({
                            type: "success",
                            message: "审批驳回"
                        });
                        this.onSubmit();
                        this.indexKey = "0";
                        this.currentOprType = null;
                    }
                });
            });
        },
        //处理批量取消
        handleBatchCancel() {
            this.$refs.batchApproveDialog.close();
        },
        //处理批量拒绝
        handleBatchReject() {
            this.isReject = true;
            this.$refs.batchForm.validate(valid => {
                if (!valid) {
                    return;
                }
                let data = this.selectStudents.map(r => {
                    return {
                        no: r.workflowNo,
                        content: this.batchForm.suggestion
                    };
                });
                rejectBatch(data).then(res => {
                    if (res.code == 200) {
                        this.$message({
                            type: "success",
                            message: "批量审批驳回"
                        });
                        this.$refs.batchApproveDialog.close();
                        this.onSubmit();
                    }
                });
            });
        },
        //处理批量通过
        handleBatchPass() {
            this.isReject = false;
            this.$refs.batchForm.validate(valid => {
                if (!valid) {
                    return;
                }
                //更新状态
                let params = this.selectStudents.map(s => {
                    return {
                        id: s.id,
                        defenseTime: s.defenseTime,
                        workflowNo: s.workflowNo
                            };
                    });
                updateDefenseTime(params).then(res => {
                    if (res.code == 200) {
                        
                        let data = this.selectStudents.map(r => {
                            return {
                                no: r.workflowNo,
                                content: this.batchForm.suggestion
                            };
                        });
                         throughBatch(data).then(res => {
                            if (res.code == 200) {
                                    this.$message({
                                    type: "success",
                                    message: "批量审批通过"
                                });
                            this.$refs.batchApproveDialog.close();
                            this.onSubmit();
                         }
                     });
                    }
                });
            });
        },
        //预览组内用户信息
        handleReviewGroup(groupId) {
            this.$refs.groupUsers.open();
            this.usersQueryForm.groupId = groupId;
            this.getGroupUsersByGroupId();
        },
        //关闭组内用户信息时初始化
        handleGroupUsersClose() {
            this.usersQueryForm.groupId = null;
            this.usersQueryForm.pageNum_ = 1;
            this.usersQueryForm.pageSize_ = 20;
            this.usersQueryForm.total_ = 0;
        },
        //组内用户信息翻页
        handleUserCurrentChange(val) {
            this.usersQueryForm.pageSize_ = val.pageSize;
            this.usersQueryForm.pageNum_ = val.pageNum;
            this.getGroupUsersByGroupId();
        },
        //获取组内用户列表
        getGroupUsersByGroupId(groupId) {
            getUserInfoListByGroupId({
                groupId: this.usersQueryForm.groupId,
                pageNum_: this.usersQueryForm.pageNum_,
                pageSize_: this.usersQueryForm.pageSize_,
                total: 0,
                userName: ""
            }).then(res => {
                if (res.code == 200) {
                    this.users = res.data.list;
                    this.usersQueryForm.total_ = res.data.total_;
                }
            });
        },
        getFormatData(data) {
            return moment(data).format("YYYY-MM-DD");
        },
        getFileName(path) {
            if (path.indexOf("/") != -1) {
                return path.substring(path.lastIndexOf("/") + 1);
            } else {
                return path;
            }
        },
        bindApproveHistory(workflowNo) {
            this.approvalHistorys = null;
            let module_ = this.defenseType == 0 ? 2 : 3;
            if (workflowNo) {
                oralApprovalHistory(workflowNo, module_).then(res => {
                    if (res.code == 200) {
                        this.approvalHistorys = res.data;
                    }
                });
            }
        },
        validateSuggestion(rule, value, callback) {
            let msg = null;
            if (this.isReject) {
                if (
                    _.isNull(this.submitForm.suggestion) ||
                    _.trim(this.submitForm.suggestion) == ""
                ) {
                    msg = "必须填写审批意见";
                }
            }
            msg ? callback(new Error(msg)) : callback();
        },
        validateBatchSuggestion(rule, value, callback) {
            let msg = null;
            if (this.isReject) {
                if (
                    _.isNull(this.batchForm.suggestion) ||
                    _.trim(this.batchForm.suggestion) == ""
                ) {
                    msg = "必须填写审批意见";
                }
            }
            msg ? callback(new Error(msg)) : callback();
        },
        getUserType(val) {
            if (val == 1) {
                return "老师";
            }
            if (val == 2) {
                return "学生";
            }
            if (val == 3) {
                return "本地用户";
            }
            return null;
        }
    }
};
</script>

<style lang="scss" scoped>
.table-detail {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #d2d4d6;
    margin-top: 15px;
    td {
        border-collapse: collapse;
        border: 1px solid #d2d4d6;
        line-height: 32px;
    }
    .label {
        text-align: right;
        background: #f5f7f9;
        color: #8896a7;
    }
    span {
        margin: 0 10px;
    }
}
#batch-dialog {
    ::v-deep .edu-dialog_body {
        padding-bottom: 10px;
    }
}
</style>